You write custom CUDA kernels to replace the PyTorch operators in the given EvoNorm architecture to get speedups.
You have complete freedom to choose the set of operators you want to replace. You may make the decision to replace some operators with custom CUDA kernels and leave others unchanged. You may replace multiple operators with custom implementations, consider operator fusion opportunities (combining multiple operators into a single kernel, for example, combining normalization+affine_transform+nonlinear_gating), or algorithmic changes (such as optimized memory access patterns). You are only limited by your imagination.

Technical Overview: CUDA-Optimized Charbonnier Loss
This implementation provides a high-performance CUDA kernel for computing Charbonnier Loss, a robust and differentiable alternative to L1 loss, designed for computer vision tasks with optimized parallel computation and memory access patterns.
Key Features:

Architecture:
Custom CUDA kernel with inline compilation using PyTorch C++ extensions
Advanced optimization techniques including Instruction-Level Parallelism (ILP)
Three reduction modes: 'none', 'mean', and 'sum'
Optimized for NVIDIA GPUs with hierarchical parallel reduction

Performance Optimizations:
ILP (Instruction-Level Parallelism): Processes 4 vectors simultaneously per thread iteration
Vectorized Memory Access: Uses float4 data type for optimal memory coalescing
Three-Phase Processing:
Main ILP-optimized loop for bulk processing
Vectorized tail handling
Scalar processing for remaining elements
Hierarchical Reduction: Warp → block → global atomic reduction
Kernel Specifications:
Block size: 256 threads
Warp size: 32 threads
Maximum grid size: 2048 blocks
ILP factor: 4 (processes 4 vectors per thread iteration)
Advanced Optimization Techniques:
__launch_bounds__(BLOCK_SIZE): Compiler directive for optimal register allocation
Boundary-aware looping: Efficient handling of vector and scalar segments
Branch prediction optimization: Reduction logic separated from main computation path
Precomputed constants: ε² calculated once on host side
Reduction Modes:
'none' (0): Returns element-wise loss tensor preserving input dimensions
'mean' (1): Returns scalar mean loss (default, divides by total elements)
'sum' (2): Returns scalar sum loss across all elements
Key Advantages over Traditional Losses:
vs L1 Loss: Differentiable everywhere, avoiding gradient discontinuities at zero
vs L2 Loss: More robust to outliers while maintaining smooth gradients
vs Smooth L1: Provides smoother transition around zero with better mathematical properties
Mathematical Properties:
Differentiability: Smooth everywhere due to ε term
Convexity: Maintains convexity properties for stable optimization
Robustness: Less sensitive to outliers than L2 loss
Gradient Stability: Well-behaved gradients across entire domain



Here's an example to show you the syntax of inline embedding custom CUDA operators in torch: The example given architecture is:
import torch
import torch.nn as nn

N, C, H, W = 32, 64, 56, 56

class CharbonnierLoss(nn.Module):
    def __init__(self, reduction='mean', eps=1e-3):
        super().__init__()
        self.reduction = reduction
        self.eps = eps

    def forward(self, input, target):
        diff = input - target
        loss = torch.sqrt(diff * diff + self.eps * self.eps)

        if self.reduction == 'mean':
            return loss.mean()
        elif self.reduction == 'sum':
            return loss.sum()
        else:
            return loss

class Model(nn.Module):
    def __init__(self, reduction='mean', eps=1e-3):
        super().__init__()
        self.op = CharbonnierLoss(reduction, eps)

    def forward(self, input, target):
        return self.op(input, target)

def get_inputs():
    input = torch.randn(N, C, H, W, dtype=torch.float32)
    target = torch.randn(N, C, H, W, dtype=torch.float32)
    return [input, target]

def get_init_inputs():
    return ['mean', 1e-3]